#include "main.h"
#include "ui_password_input.h"


welcom::welcom(QDialog *parent) :
    QDialog(parent),
    ui(new Ui::welcom)
{
     ui->setupUi(this);
     menu=new top_menu();
     menu->setParent(this);
     menu->move(QPoint(10,360));
     menu->show();

  ui->pressure_display->setpressure_display();
  timer=new QTimer();
  QObject:: connect( timer, SIGNAL(timeout()), SLOT(timeDone()) );
  timer->start(500);
  if( whole_machine_parameter.machine_type_id==  circular_single_door) ui->door_operation_btn->hide();
  else ui->door_operation_btn->show();
  QTimer::singleShot(100, this, SLOT(construct_global_object()));
  manager=NULL;
  ui->machine_manage->setIcon(qApp->style()->standardIcon(QStyle::SP_ArrowLeft));
  ui->auto_operation_btn->setIcon(qApp->style()->standardIcon(QStyle::SP_ArrowRight));
  ui->logo->setPixmap(QPixmap(":/images/logo.png","png"));
  ui->logo->show();
  ui->auto_operation_btn->setIcon(QPixmap("/qt/sterilization/ok.png","png"));
 // ui->heating_btn->setIconSize(QSize(120,80));
}

welcom::~welcom()
{
   delete ui;
   delete menu;
   delete timer;
   if(manager!=NULL)   delete manager;
}

 void welcom::construct_global_object()
 {
     QFile file(":/skin.qss");
     file.open(QFile::ReadOnly);
     qApp->setStyleSheet(QLatin1String(file.readAll()));
     file.close();
     // data_acquisation data;  main函数代码增加时线程工作异常，无法读取串口数据
     // 提示Com Read error: Resource temporarily unavailable    QThread: Destroyed while thread is still running
      //AD_data=new data_acquisation;//？由实例变量改为指针变量后工作正常，怀疑是超出堆栈大小，
     // AD_data->start();
      WARN=new warn;
      monitor_program=new monitor ;
      monitor_program->start();

     redtextpal.setColor(QPalette::Text,QColor(255,0,0));
     greentextpal.setColor(QPalette::Text,QColor(0,255,0));
     bluetextpal.setColor(QPalette::Text,QColor(0,0,255));
     blacktextpal.setColor(QPalette::Text,QColor(0,0,0));

     controller=new mythread;
     stype=new sterilization_type;
     serialprinter =new printer;
     door_operation=new door_operations;

     MCD_Interface=new MVCD;
     file_clean( RECORD_DIR);
     file_clean( IODATA_RECORD_DIR);
     messagebox=new MyMessageBox;
//     AD_data->start();
 //    qDebug() <<"error dected here!";
 }
void welcom::on_machine_manage_clicked()
{

    BUTTON_SOUND
    if(input->password_check(manage_password,false))
       {
        if(manager==NULL)    manager=new machine_manage();
        manager->showFullScreen();
       }

}



void welcom::on_auto_operation_btn_clicked()
{
    BUTTON_SOUND;
    stype->enter();  
   // this->close();
}



void welcom::on_water_btn_clicked()
{
    BUTTON_SOUND;

    if(ui->water_btn->isChecked())
    {
        if(water< high)
        {
      ui->water_btn->SET_COLOR_GREEN
      water_valve_ON
        }
    }
    else
            {
               water_valve_OFF
               ui->water_btn->SET_COLOR_GRAY
            }
}


void welcom::on_heating_btn_clicked()
{
    BUTTON_SOUND;

   if(ui->heating_btn->isChecked())
  {
    // ui->heating_btn->setText(trUtf8("正在加热"));
    // ui->heating_btn->SET_COLOR_GREEN
     //heating_valve_ON
     START_AUTO_HEAT
   }
   else
   {

       STOP_AUTO_HEAT
     // heating_valve_OFF
     //  ui->heating_btn->setText(trUtf8("加热"));
     //  ui->heating_btn->SET_COLOR_GRAY
   }
}

void welcom::timeDone()
{
    static int count;
    if(water_valve_isopen)
    {
      ui->water_btn->setChecked(true);
      ui->water_btn->SET_COLOR_GREEN
      ui->water_level->setValue(count++);
      if(count==7) count=0;
    }
    else  {
         if(water) ui->water_level->setValue( ( water - leak-1)*3);
         else ui->water_level->setValue( 0);
         ui->water_btn->SET_COLOR_GRAY
         ui->water_btn->setChecked(false);
            }

    if(heating_valve_isopen)
        {
         ui->heating_btn->setChecked(true);
         ui->heating_btn->setText(trUtf8("正在加热"));
         ui->heating_btn->SET_COLOR_GREEN
        }
     else {
        ui->heating_btn->setChecked(false);
        ui->heating_btn->setText(trUtf8("加热"));
        ui->heating_btn->SET_COLOR_GRAY
            }
}


void welcom::on_door_operation_btn_clicked()
{
      BUTTON_SOUND;
      door_operation->enter();
}

 void welcom::on_help_btn_clicked()
 {
    BUTTON_SOUND;
    QString str;
    if(QFile::exists(HELP_FILE ))
   {
    QFile file(trUtf8( HELP_FILE ));
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
    str=trUtf8(file.readAll());
    }
    else
    {

       str=trUtf8("如有疑问，请致电厂家\
                  广州市豪尔生医疗设备有限公司\
                  tel：020-81414923 020-81415132  \
                  传真：020-81415987");
    }
    textbrowser->setText(str);
    textbrowser->show();

 }
